package com.yjhb.android.sbz.fragment.mytask;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;

import com.yjhb.android.sbz.activity.NoPassDetailActivity;
import com.yjhb.android.sbz.dialog.TipOffDialog;
import com.yjhb.android.sbz.dialog.TipsDialog;
import com.yjhb.android.sbz.entity.FailDetail;
import com.yjhb.android.sbz.entity.MyTask;
import com.yjhb.android.sbz.enums.TaskStatus;
import com.yjhb.android.sbz.manager.ResManager;
import com.yjhb.android.sbz.tool.Tool;
import com.jojo.android.zxlib.tool.ZxSpanTool;

/**
 * 创建者 zx
 * 创建时间 2020/12/17 15:12
 */
public class UnPassFragment extends MyTaskListFragment {
    private final String TAG = "FailFragment";

    @Override
    public CharSequence getTitle() {
        return "未通过";
    }

    @Override
    protected void onLoadData(int size, int current) {
        presenter.getOrderList(TaskStatus.TASK_STATUS_FAIL.getStatus(), size, current);
    }

    @Override
    public void onViewClick(View view, String msg, int index, Object o) {
        MyTask myTask = (MyTask) o;
        if (msg.equals("btn1")) {
            showTips1(myTask);
        } else if (msg.equals("btn2")) {
            showTips(myTask);
        } else if (msg.equals("lookDetail")) {
            FailDetail failDetail = new FailDetail();
            failDetail.setRejectReason(dataSet.get(index).getRejectReason());
            failDetail.setRejectReasonImg(dataSet.get(index).getRejectImgs());
            Intent intent = new Intent(getContext(), NoPassDetailActivity.class);
            intent.putExtra("failDetail", failDetail);
            startActivity(intent);
        }
    }

    @Override
    public void onItemClick(int index, Object o) {
//        super.onItemClick(index, o);
        MyTask myTask = (MyTask) o;
        Tool.startEditTaskDetailActivity(getContext(), myTask.getTaskId());
    }

    private void showTips1(MyTask myTask) {
        String tips = new StringBuilder("您还有")
                .append(2 - myTask.getSubmitCounter())
                .append("次重新提交的机会，请谨慎修改！！！")
                .toString();
        TipsDialog tipsDialog = new TipsDialog(getContext());
        tipsDialog.setContent(ZxSpanTool.ColorSpan(tips, 3, 4, ResManager.getThemeColor()));
        tipsDialog.setTitle("提示");
        tipsDialog.setContentGravity(Gravity.CENTER);
        tipsDialog.setSubmitText("继续");
        tipsDialog.setCancelText("我再想想");
        tipsDialog.setOnClickListener(new TipsDialog.OnClickListener() {
            @Override
            public void onClick(int type) {
                tipsDialog.dismiss();
                if (TipsDialog.TYPE_SUBMIT == type) {
                    Tool.startReeditTaskDetailActivity(getContext(), myTask.getTaskId(), myTask.getId());
                }
            }
        });
        tipsDialog.show();
    }

    private void showTips(MyTask myTask) {
        final TipsDialog tipsDialog = new TipsDialog(getContext());
        tipsDialog.setTitle("提示");
        CharSequence charSequence = "若任务不通过，可根据原因先与悬赏主沟通，再重新提交任务。\n" +
                "一旦举报败诉，任务无法再重新提交审核。若存在恶意举报，直接封号。\n确定举报？";
        String highLight = "确定举报？";
//        String highLight1 = "*";
        int index = charSequence.toString().indexOf(highLight);
//        int index1 = charSequence.toString().indexOf(highLight1);
        charSequence = ZxSpanTool.ColorSpan(charSequence, index, index + highLight.length(), ResManager.getThemeColor());
//        charSequence = ZxSpanTool.ColorSpan(charSequence, index1, index1 + highLight1.length(), ResManager.getThemeColor());
        tipsDialog.setContent(charSequence);
        tipsDialog.setContentGravity(Gravity.CENTER);
        tipsDialog.setSubmitText("确定");
        tipsDialog.setOnClickListener(new TipsDialog.OnClickListener() {
            @Override
            public void onClick(int type) {
                tipsDialog.dismiss();
                if (type == TipsDialog.TYPE_SUBMIT) {
                    TipOffDialog tipOffDialog = new TipOffDialog((Activity) getContext()
                            , TipOffDialog.REPORT_TYPE_CHECK, myTask.getUserId(), "" + myTask.getId());
                    tipOffDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            onLoadData(size, current);
                        }
                    });
                    tipOffDialog.show();
                }

            }
        });
        tipsDialog.show();
    }
}
